//
//  BreakageVC.m
//  CJRailTransport
//
//  Created by Hank on 2018/1/22.
//  Copyright © 2018年 amplity. All rights reserved.
//
#define CarrierTitle          @"请选择承运商"
#define DamagedLocationTitle  @"请选择受损位置"
#define DamagedExtentTitle    @"请选择受损程度"

#import "BreakageVC.h"
#import "STPickerDate.h"
#import "STPickerSingle.h"
#import "UIView+Expand.h"
#import "UITextView+WZB.h"
#import "UIButton+Expand.h"

@interface BreakageVC ()<STPickerDateDelegate,STPickerSingleDelegate, UITextViewDelegate>

@end

@implementation BreakageVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // 设置导航栏
    [self setNavC];
    // 设置界面属性
    [self setViewAttribute];
    // 设置圆角
    [self setRadius];
    // 设置BarButtonItem
    [self setBarButtonItem];
}

#pragma mark - 导航栏
- (void)setNavC
{
    self.title = @"质损";
    // 设置导航栏颜色
    BasicNavigationController *nVC = (BasicNavigationController *)self.navigationController;
    nVC.themeColor = [UIColor whiteColor];
    nVC.tintColor = [UIColor darkGrayColor];
}

// 设置界面属性
- (void)setViewAttribute
{
    self.view.backgroundColor = [UIColor whiteColor];
    // TextView设置
    [self loadTextView];
}

// TextView设置
- (void)loadTextView
{
    // 设置placeholder
    self.detailTV.wzb_placeholder = @"请对损坏情况详细描述";
    // 设置placeholder的颜色
    self.detailTV.wzb_placeholderColor = DefaultRadiusGray;
}

// 设置BarButtonItem
- (void)setBarButtonItem
{
    UIButton *rightItemBtn = [UIButton setLeftOrRightButton:nil direction:@"right" title:@"提交"];
    [rightItemBtn addTarget:self action:@selector(rightItemAction) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightItemBtn];
}

#pragma mark - Radius
// 设置圆角
- (void)setRadius
{
    [self.findDateBtn radiusView:3 backgroundColor:[UIColor clearColor] borderWidth:0.5 borderColor:DefaultRadiusGray];
    [self.carrierBtn radiusView:3 backgroundColor:[UIColor clearColor] borderWidth:0.5 borderColor:DefaultRadiusGray];
    [self.damagedLocationBtn radiusView:3 backgroundColor:[UIColor clearColor] borderWidth:0.5 borderColor:DefaultRadiusGray];
    [self.damagedExtentBtn radiusView:3 backgroundColor:[UIColor clearColor] borderWidth:0.5 borderColor:DefaultRadiusGray];
    // 设置TextView圆角
    self.detailTV.layer.cornerRadius = 3;
    self.detailTV.layer.backgroundColor = [UIColor clearColor].CGColor;
    self.detailTV.layer.borderWidth = 0.5;
    self.detailTV.layer.borderColor = DefaultRadiusGray.CGColor;
}

#pragma mark - Picker
// 显示日期选择器
- (void)showDatePicker
{
    // 创建日期选择器
    STPickerDate *datePicker = [[STPickerDate alloc]init];
    [datePicker setDelegate:self];
    [datePicker setYearLeast:2000];
    [datePicker setYearSum:50];
    [datePicker setContentMode:STPickerContentModeBottom];
    [datePicker show];
}
// 显示内容选择器
- (void)showContentPicker:(NSMutableArray *)dataArray pickerTitle:(NSString *)pickerTitle
{
    // 创建内容选择器
    STPickerSingle *pickerSingle = [[STPickerSingle alloc]init];
    // 添加数据
    [pickerSingle setArrayData:dataArray];
    // 添加标题
    [pickerSingle setTitle:pickerTitle];
    [pickerSingle setContentMode:STPickerContentModeBottom];
    [pickerSingle setDelegate:self];
    // 显示内容选择器
    [pickerSingle show];
}

#pragma mark - itemAction
- (void)rightItemAction
{
    
}

#pragma mark - Action
// 发现日期 Action
- (IBAction)findDateAction:(UIButton *)sender
{
    // 收起键盘
    [self packUpKeyboard];
    // 显示日期选择器
    [self showDatePicker];
}
// 承运商 Action
- (IBAction)carrierAction:(UIButton *)sender
{
    // 收起键盘
    [self packUpKeyboard];
    // 显示内容选择器
    [self showContentPicker:[NSMutableArray arrayWithArray:@[@"承运商测试1",@"承运商测试2",@"承运商测试3",@"承运商测试4",@"承运商测试5",@"承运商测试6"]] pickerTitle:CarrierTitle];
}
// 受损位置 Action
- (IBAction)damagedLocationAction:(UIButton *)sender
{
    // 收起键盘
    [self packUpKeyboard];
    // 显示内容选择器
    [self showContentPicker:[NSMutableArray arrayWithArray:@[@"受损位置测试1",@"受损位置测试2",@"受损位置测试3",@"受损位置测试4",@"受损位置测试5",@"受损位置测试6"]] pickerTitle:DamagedLocationTitle];
}
// 受损程度 Action
- (IBAction)damagedExtentAction:(UIButton *)sender
{
    // 收起键盘
    [self packUpKeyboard];
    // 显示内容选择器
    [self showContentPicker:[NSMutableArray arrayWithArray:@[@"受损程度测试1",@"受损程度测试2",@"受损程度测试3",@"受损程度测试4",@"受损程度测试5",@"受损程度测试6"]] pickerTitle:DamagedExtentTitle];
}

#pragma mark - Extract 提取
// 收起键盘
- (void)packUpKeyboard
{
    [self.appliancesNoTF resignFirstResponder];
    [self.findLocationTF resignFirstResponder];
    [self.detailTV resignFirstResponder];
}

#pragma mark - pickerDateDelegate
// date
-(void)pickerDate:(STPickerDate *)pickerDate year:(NSInteger)year month:(NSInteger)month day:(NSInteger)day {
    // 更新日期
    [self.findDateBtn setTitle:[NSString stringWithFormat:@"  %d-%@-%@", year, [self digitJudge:month], [self digitJudge:day]] forState:UIControlStateNormal];
}
// 数字位数判断
- (NSString *)digitJudge:(NSInteger)number
{
    // 转换的字符串
    NSString *numberStr;
    
    if (number < 10) {
        numberStr = [NSString stringWithFormat:@"0%d",number];
    }else{
        numberStr = [NSString stringWithFormat:@"%d",number];
    }
    return numberStr;
}

// content
- (void)pickerSingle:(STPickerSingle *)pickerSingle selectedTitle:(NSString *)selectedTitle
{
    if ([pickerSingle.title isEqualToString:CarrierTitle]) {
        [self.carrierBtn setTitle:[NSString stringWithFormat:@"  %@", selectedTitle] forState:UIControlStateNormal];
    }else if ([pickerSingle.title isEqualToString:DamagedLocationTitle]) {
        [self.damagedLocationBtn setTitle:[NSString stringWithFormat:@"  %@", selectedTitle] forState:UIControlStateNormal];
    }else if ([pickerSingle.title isEqualToString:DamagedExtentTitle]) {
        [self.damagedExtentBtn setTitle:[NSString stringWithFormat:@"  %@", selectedTitle] forState:UIControlStateNormal];
    }
}

- (void)dealloc
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
